var express = require('express');
var request = require('request');
var router = express.Router();

var zdbDao=require('../models/zdbBase.js');
const members = new zdbDao("members"); //场地表资源表


router.get('/sport/clm/userphone',function(req, res){
    console.log('---/sport/clm/userphone---',req.query.wxopenId);
    var data ={
        wxopenId: req.query.wxopenId || "ovKRTwQkp7YMnkAiqBV2retvNXSU"
    }

    members.findByColumn(data,function(err, result){
        console.log('---err:---',err,result.length);
        var phone ='';
        if(err){

        }else{
            if(result.length>0){

                phone = result[0].phone;
            }
            console.log("result:",phone);
        }

        res.json({
            phone:phone
        });
    })

})

/**
 * 提交修改用户电话路由;
 * @data 要修改的数据;
 * @obj 查询条件;
 *
 */

router.get('/sport/clm/updatephone',function(req, res){
    console.log(req.query.wxopenId);
    console.log(req.query.phone);
    var obj ={
        wxopenId: req.query.wxopenId || "ovKRTwQkp7YMnkAiqBV2retvNXSU"
    };
    var data = {
        phone:req.query.phone ||""
    };

    members.updateByColumns( data,obj, function(err, result){
        //console.log("result",result.affectedRows);
        if(result.affectedRows === 1){
            res.json({
                code:"200"
            });
        }else{
            res.json({
                code:"300"
            });
        }

    })

})


module.exports = router;